home *** CD-ROM | disk | FTP | other *** search
/ Micromanía 92 / CDMM92_1.ISO / SOF 2 SDK / sof2sdk-101.msi / _92D6AC311BB48EBA344BBABC89DA6AB0 / _24FB7F13BBE743AB97E21E18714DBF5F < prev    next >
Encoding:
Text File  |  2002-06-25  |  3.7 KB  |  214 lines

  1. // Copyright (C) 2001-2002 Raven Software
  2. //
  3.  
  4. #include "g_local.h"
  5.  
  6. /*
  7. ==============
  8. OtherTeam
  9. ==============
  10. */
  11. int OtherTeam(team_t team) 
  12. {
  13.     if (team==TEAM_RED)
  14.         return TEAM_BLUE;
  15.     else if (team==TEAM_BLUE)
  16.         return TEAM_RED;
  17.     return team;
  18. }
  19.  
  20. /*
  21. ==============
  22. TeamName
  23. ==============
  24. */
  25. const char *TeamName(team_t team)  
  26. {
  27.     switch ( team )
  28.     {
  29.         case TEAM_RED:
  30.             return "RED";
  31.  
  32.         case TEAM_BLUE:
  33.             return "BLUE";
  34.  
  35.         case TEAM_FREE:
  36.             return "FREE";
  37.  
  38.         case TEAM_SPECTATOR:
  39.             return "SPECTATOR";
  40.     }
  41.  
  42.     return "";
  43. }
  44.  
  45. /*
  46. ==============
  47. OtherTeamName
  48. ==============
  49. */
  50. const char *OtherTeamName(team_t team) 
  51. {
  52.     if (team==TEAM_RED)
  53.         return TeamName ( TEAM_BLUE );
  54.     else if (team==TEAM_BLUE)
  55.         return TeamName ( TEAM_BLUE );
  56.  
  57.     return TeamName ( team );
  58. }
  59.  
  60. /*
  61. ==============
  62. TeamColorString
  63. ==============
  64. */
  65. const char *TeamColorString(team_t team) 
  66. {
  67.     if (team==TEAM_RED)
  68.         return S_COLOR_RED;
  69.     else if (team==TEAM_BLUE)
  70.         return S_COLOR_BLUE;
  71.     else if (team==TEAM_SPECTATOR)
  72.         return S_COLOR_YELLOW;
  73.  
  74.     return S_COLOR_WHITE;
  75. }
  76.  
  77. // NULL for everyone
  78. void QDECL PrintMsg( gentity_t *ent, const char *fmt, ... ) 
  79. {
  80.     char        msg[1024];
  81.     va_list        argptr;
  82.     char        *p;
  83.     
  84.     va_start (argptr,fmt);
  85.     if (vsprintf (msg, fmt, argptr) > sizeof(msg)) 
  86.     {
  87.         Com_Error ( ERR_FATAL, "PrintMsg overrun" );
  88.     }
  89.     va_end (argptr);
  90.  
  91.     // double quotes are bad
  92.     while ((p = strchr(msg, '"')) != NULL)
  93.     {
  94.         *p = '\'';
  95.     }
  96.  
  97.     trap_SendServerCommand ( ( (ent == NULL) ? -1 : ent-g_entities ), va("print \"%s\"", msg ));
  98. }
  99.  
  100. /*
  101. ==============
  102. G_AddTeamScore
  103.  
  104. used for gametype > GT_TDM
  105. for gametype GT_TDM the level.teamScores is updated in AddScore in g_combat.c
  106. ==============
  107. */
  108. void G_AddTeamScore( team_t team, int score ) 
  109. {
  110.     // Dont allow negative scores to affect the team score.  The reason for this is 
  111.     // that negative scores come from the actions of one bad player and a single player
  112.     // can cause a team to loose because he/she wants to just kill the rest of their team, or
  113.     // continue to kill themselves.
  114.     if ( score < 0 )
  115.     {
  116.         return;
  117.     }
  118.  
  119.     level.teamScores[ team ] += score;
  120. }
  121.  
  122. /*
  123. ==============
  124. OnSameTeam
  125. ==============
  126. */
  127. qboolean OnSameTeam( gentity_t *ent1, gentity_t *ent2 ) 
  128. {
  129.     if ( !ent1->client || !ent2->client ) 
  130.     {
  131.         return qfalse;
  132.     }
  133.  
  134.     if ( !level.gametypeData->teams ) 
  135.     {
  136.         return qfalse;
  137.     }
  138.  
  139.     if ( ent1->client->sess.team == ent2->client->sess.team ) 
  140.     {
  141.         return qtrue;
  142.     }
  143.  
  144.     return qfalse;
  145. }
  146.  
  147. /*
  148. ===========
  149. Team_GetLocation
  150.  
  151. Report a location for the player. Uses placed nearby target_location entities
  152. ============
  153. */
  154. gentity_t *Team_GetLocation(gentity_t *ent, qboolean pvs )
  155. {
  156.     gentity_t        *eloc, *best;
  157.     float            bestlen, len;
  158.     vec3_t            origin;
  159.  
  160.     best = NULL;
  161.     bestlen = 3*8192.0*8192.0;
  162.  
  163.     VectorCopy( ent->r.currentOrigin, origin );
  164.  
  165.     for (eloc = level.locationHead; eloc; eloc = eloc->nextTrain) 
  166.     {
  167.         len = ( origin[0] - eloc->r.currentOrigin[0] ) * ( origin[0] - eloc->r.currentOrigin[0] )
  168.             + ( origin[1] - eloc->r.currentOrigin[1] ) * ( origin[1] - eloc->r.currentOrigin[1] )
  169.             + ( origin[2] - eloc->r.currentOrigin[2] ) * ( origin[2] - eloc->r.currentOrigin[2] );
  170.  
  171.         if ( len > bestlen ) 
  172.         {
  173.             continue;
  174.         }
  175.  
  176.         if ( pvs && !trap_InPVS( origin, eloc->r.currentOrigin ) ) 
  177.         {
  178.             continue;
  179.         }
  180.  
  181.         bestlen = len;
  182.         best = eloc;
  183.     }
  184.  
  185.     return best;
  186. }
  187.  
  188.  
  189. /*
  190. ===========
  191. Team_GetLocationMsg
  192. ============
  193. */
  194. qboolean Team_GetLocationMsg ( gentity_t *ent, char *loc, int loclen )
  195. {
  196.     gentity_t *best;
  197.  
  198.     best = Team_GetLocation( ent, qtrue );
  199.     if ( !best )
  200.     {
  201.         best = Team_GetLocation( ent, qfalse );
  202.     }
  203.     
  204.     if (!best)
  205.     {
  206.         return qfalse;
  207.     }
  208.  
  209.     Com_sprintf(loc, loclen, "%s", best->message);
  210.  
  211.     return qtrue;
  212. }
  213.  
  214.